import React from 'react'
import {withRouter} from 'react-router-dom'
import {LoginModel} from '../api/login'

import {connect} from 'react-redux'
import {setName} from '../redux/user.redux'


const loginModel=new LoginModel()
@withRouter
@connect(
  state=>state.user,
  {setName}
)
class CheckLogin extends React.Component {
   componentDidMount() {
    const loginTest= loginModel.loginTest();
    if(loginTest===false){
      this.props.history.push('/login')
    }else{
      loginTest
        .then(result=>{
          if(result.code!==0){
            this.props.history.push('/login')
          }else{
            this.props.setName(result.data)
          }
        }).catch(err=>{

      })
    }



  }

  render() {
    return null
  }
}

export default CheckLogin
